from PyQt5.QtWidgets import QApplication,QLabel,QWidget,QVBoxLayout
from PyQt5.QtCore import  Qt
from PyQt5.QtGui import QPixmap,QPalette
import sys
class WinDemo(QWidget):
    def __init__(self):
        super().__init__()
        label1=QLabel()
        label2 = QLabel()
        label3 = QLabel()
        label4 = QLabel()
        label1.setText("这是一个文本标签")
        label1.setAutoFillBackground(True)
        palette=QPalette()
        palette.setColor(QPalette.Window,Qt.blue)
        label1.setPalette(palette)
        label1.setAlignment(Qt.AlignCenter)
        vbox=QVBoxLayout()
        vbox.addWidget(label1)
        self.setLayout(vbox)
        self.setWindowTitle("label案例")
        label2.setText("<a href='http://www.baidu.com'>label gui</a>")
        vbox.addWidget(label2)
        label2.setToolTip("超链接")
        #默认是不允许开启超链接
        label2.setOpenExternalLinks(True)
        label3.setAlignment(Qt.AlignCenter)
        label3.setToolTip("图片标签")
        label3.setPixmap(QPixmap('panda.jpg'))
        vbox.addWidget(label3)
        label4.setText("<a href='#'>label4</a>")
        vbox.addWidget(label4)
        label4.linkActivated.connect(link_clicked)
        label4.linkHovered.connect(link_hovered)
def link_clicked():
    print("点击时触发事件")
def link_hovered():
    print("鼠标滑过")
if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=WinDemo()
    win.show()
    sys.exit(app.exec_())